{  Problem: http://codeforces.ru/problemset/problem/96/B
	  Verdict: Accepted
}
uses
        SysUtils, Math;

var
        n,cc,l,r,c,mt:longint;
        s:string;
        a:array[0..10010] of int64;

procedure go(k,t,tt:longint);

var
        code:longint;

begin
s:=s+inttostr(k);
if (t=mt) and (tt=mt) then begin
        inc(cc);
        val(s,a[cc],code);
        delete(s,length(s),1);
        exit;
end;
if t<mt then go(4,t+1,tt);
if tt<mt then go(7,t,tt+1);
delete(s,length(S),1);
end;

begin
read(n);
cc:=0;
s:='';
for mt:=1 to 5 do begin
        go(4,1,0);
        go(7,0,1);
end;
l:=1;
r:=cc;
while r-l>1 do begin
        c:=(l+r) shr 1;
        if a[c]>n then r:=c else l:=c;
end;
if a[l]>=n then write(a[l]) else write(a[l+1]);
end.